﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.ListItemCollection", ServerTypeId="{1722df25-a4d3-44bb-a1c6-04dbb90e9d91}")]
    public class ListItemCollection : ClientObjectCollection<ListItem>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public ListItemCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public ListItem GetById(int id)
        {
            Dictionary<int, ListItem> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetById", out obj2))
            {
                dictionary = (Dictionary<int, ListItem>) obj2;
            }
            else
            {
                dictionary = new Dictionary<int, ListItem>();
                base.ObjectData.MethodReturnObjects["GetById"] = dictionary;
            }
            ListItem item = null;
            if (!dictionary.TryGetValue(id, out item))
            {
                item = new ListItem(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetById", new object[] { id }));
                dictionary[id] = item;
            }
            return item;
        }

        public ListItem GetById(string id)
        {
            return this.GetByStringId(id);
        }

        [Remote]
        internal ListItem GetByStringId(string sId)
        {
            Dictionary<string, ListItem> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetByStringId", out obj2))
            {
                dictionary = (Dictionary<string, ListItem>) obj2;
            }
            else
            {
                dictionary = new Dictionary<string, ListItem>();
                base.ObjectData.MethodReturnObjects["GetByStringId"] = dictionary;
            }
            ListItem item = null;
            if (!dictionary.TryGetValue(sId, out item))
            {
                item = new ListItem(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetByStringId", new object[] { sId }));
                dictionary[sId] = item;
            }
            return item;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            string str;
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag && (((str = peekedName) != null) && (str == "ListItemCollectionPosition")))
            {
                flag = true;
                reader.ReadName();
                base.ObjectData.Properties["ListItemCollectionPosition"] = reader.Read<Microsoft.SharePoint.Client.ListItemCollectionPosition>();
            }
            return flag;
        }

        [Remote]
        public Microsoft.SharePoint.Client.ListItemCollectionPosition ListItemCollectionPosition
        {
            get
            {
                base.CheckUninitializedProperty("ListItemCollectionPosition");
                return (Microsoft.SharePoint.Client.ListItemCollectionPosition) base.ObjectData.Properties["ListItemCollectionPosition"];
            }
        }
    }
}

